package com.jr.webrtc.controller;

import com.jr.webrtc.model.*;
import com.jr.webrtc.repository.*;
import com.jr.webrtc.config.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/rooms")
public class RoomController {

    @Autowired
    private RoomRepository roomRepository;

    @GetMapping
    public List<Room> getAllRooms() {
        return roomRepository.findAll();
    }

    @PutMapping("/{id}")
    public ResponseEntity<String> updateRoom(@PathVariable Long id, @RequestBody Room updatedRoom) {
        return roomRepository.findById(id)
            .map(room -> {
                room.setName(updatedRoom.getName());
                room.setOwnerid(updatedRoom.getOwnerid());
                room.setCapacity(updatedRoom.getCapacity());
                room.setDescription(updatedRoom.getDescription());
                
                roomRepository.save(room);
                return ResponseEntity.ok("房间更新成功");
            })
            .orElse(ResponseEntity.notFound().build());
    }
}